<template>
	<view :class="['content',title!='用户手册' ? 'p30' : '']">
		<u-parse :content="content"></u-parse>
	</view>
</template>

<script>
	import {
		marked
	} from "marked"
	
	import {
		getCartypeDetailAPI
	} from "@/api/api/car.js"

	export default {
		name: "agreement",
		data() {
			return {
				content: '',
				title:'',
			}
		},
		
		onLoad(params) {
			this.title = params.title;
			uni.setNavigationBarTitle({
				title: params.title
			})
			if (params.title == '用户协议') {
				uni.request({
					url: 'https://iot-device-saas.oss-cn-shenzhen.aliyuncs.com/public/userAgreement1.js',
				}).then(res => {
					if(res[1] && res[1].data){
						this.content = marked(res[1].data.replace(/`/g,''));
					}
				})
			} else if (params.title == '隐私保护协议') {
				uni.request({
					url: 'https://iot-device-saas.oss-cn-shenzhen.aliyuncs.com/public/privateAgreement.js',
				}).then(res => {
					if(res[1] && res[1].data){
						this.content = marked(res[1].data.replace(/`/g,''));
					}
				})
			} else if (params.title == '订阅付费须知') {
				uni.request({
					url: 'https://iot-device-saas.oss-cn-shenzhen.aliyuncs.com/public/payAgreement.js',
				}).then(res => {
					if(res[1] && res[1].data){
						this.content = marked(res[1].data.replace(/`/g,''));
					}
				})
			}else if (params.title == '用户手册' || params.title == '保养手册') {
				getCartypeDetailAPI(params.id).then(([err, data]) => {
					if (err) return;
					this.content = params.title == '用户手册' ? data.userHandbook : data.maintainHandbook;
				})
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
